//
//  MineTableViewController.m
//  project
//
//  Created by 李腾昊 on 2017/10/19.
//  Copyright © 2017年 Macmini. All rights reserved.
//

#import "MineTableViewController.h"

#import "MineHeaderView.h"
#import "PageViewController.h"
#import "WorkingTableViewController.h"
#import "AccountViewController.h"
#import "ADsViewController.h"
#import "RealNameViewController.h"
#import "UIStoryboard+load.h"
#import "CLBTC_HTCAddressVC.h"
#import "MyAdsViewController.h"
#import "AppDelegate.h"
#import "LoginViewController.h"
#import "TibiAddressViewController.h"
#import "SetTableViewController.h"

@interface MineTableViewController ()

@property (nonatomic, strong)MineHeaderView *mineHeaderView;
@property (weak, nonatomic) IBOutlet UIImageView *guangKao;
@property (weak, nonatomic) IBOutlet UIImageView *diZhi;
@property (weak, nonatomic) IBOutlet UIImageView *shouBi;
@property (weak, nonatomic) IBOutlet UIImageView *sheZhi;
@property (weak, nonatomic) IBOutlet UIImageView *wenTi;
@property (weak, nonatomic) IBOutlet UIImageView *guanYuWoMen;
@property (weak, nonatomic) IBOutlet UIImageView *keFu;
@property (weak, nonatomic) IBOutlet UIImageView *tuiJian;
@property (weak, nonatomic) IBOutlet UIImageView *tuiChu;


@end

@implementation MineTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"个人中心";
    self.navigationItem.rightBarButtonItem.title = @"帮助";
    self.tableView.sectionHeaderHeight = 149;
    self.tableView.tableFooterView = [UIView new];
//    self.tableView.contentOffset = CGPointMake(0, 149);
    [self setupNavBar];
    
    [self.tableView reloadData];
}
- (IBAction)shimingaction:(id)sender {
    RealNameViewController *real = [UIStoryboard loadStoryboard:@"RealNameViewController"];
    real.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:real animated:YES];
}



- (void)setupNavBar {
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setTitle:@"帮助" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
    
}
- (void)viewWillAppear:(BOOL)animated {
    
//    if (@available(iOS 11.0, *))
//    {
//        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//    }
//    else
//    {
//        self.automaticallyAdjustsScrollViewInsets = NO;
//    }
//      self.tableView.tableHeaderView = self.mineHeaderView;
    
    [super viewWillAppear:animated];
}


- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
    
}

- (void)viewDidAppear:(BOOL)animated {
     [self configureImageView];
    [super viewDidAppear:animated];
}

- (void)configureImageView {
    
    UIColor *color = [UIColor colorWithRed:69/255.0 green:69/255.0 blue:83/255.0 alpha:1/1.0];
    self.guangKao.image = [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e62c", 15.1, color)];
    self.diZhi.image = [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e6d4", 18, color)];
    self.shouBi.image = [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e744", 18, color)];
    self.sheZhi.image = [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e600",18 , color)];
    self.wenTi.image =[UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e682",18 , color)];
    self.guanYuWoMen.image =[UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e620",18 , color)];
    self.keFu.image =[UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e607",18 , color)];
    self.tuiJian.image =[UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e64b",16.4 , color)];
    self.tuiChu.image =[UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e612",18 , color)];
                                                                
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
       return  10;
}

//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
//
//
//    return self.mineHeaderView;
//}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if([cell respondsToSelector:@selector(setLayoutMargins:)]){
        [cell setLayoutMargins:UIEdgeInsetsMake(0, 21, 0, 21)];
    }
    
    if([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsMake(0, 21, 0, 21)];
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0 & indexPath.row == 0) { //我的广告
     
        if (!loginuserInfo.nickName) { //判断是否设置昵称。进行交互
            ConfriusernameViewController *confriusernameVC = [ConfriusernameViewController new];
            self.hidesBottomBarWhenPushed= YES;
            [self.navigationController pushViewController:confriusernameVC animated:YES];
            self.hidesBottomBarWhenPushed = NO;
            
        } else {
            MyAdsViewController *adsVC = [MyAdsViewController new];
            adsVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:adsVC animated:YES];
        }
        
    }
    
    if (indexPath.section == 0 & indexPath.row == 1) { //收款地址
        AccountViewController *accoutVC = [AccountViewController new];
        accoutVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:accoutVC animated:YES];
      
    }
    
    if (indexPath.section == 0 & indexPath.row == 2) { //收币地址
     //   CLBTC_HTCAddressVC *accoutVC = [CLBTC_HTCAddressVC new];
        TibiAddressViewController *tibiAddressVC = [TibiAddressViewController new];
        tibiAddressVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:tibiAddressVC animated:YES];
//        self.hidesBottomBarWhenPushed = NO;
    }
    
    if (indexPath.section == 1 & indexPath.row == 0) {
        
        SetTableViewController *setTVC = [[UIStoryboard storyboardWithName:@"SetTableViewController" bundle:nil] instantiateViewControllerWithIdentifier:@"setTableViewController"];
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:setTVC animated:YES];
       
    }
}
- (void)viewDidLayoutSubviews {
//    self.mineHeaderView.height = 149;
    [super viewDidLayoutSubviews];
    
}


#pragma mark 懒加载
-(MineHeaderView *)mineHeaderView
{
    if(!_mineHeaderView)
      
    
    _mineHeaderView = [[[ NSBundle mainBundle] loadNibNamed:@"MineHeaderView" owner:nil options:nil]lastObject];
    _mineHeaderView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 149);
    
//    self.tableView.tableHeaderView = _mineHeaderView;
    
    return _mineHeaderView;
}



@end
